package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.base.image;
import com.hdax.dm.beans.item.Item;
import com.hdax.dm.beans.item.ItemType;
import com.hdax.dm.beans.item.cinema;
import com.hdax.dm.dto.floorDto;
import com.hdax.dm.feign.imagefeign;
import com.hdax.dm.mappers.ItemMapper;
import com.hdax.dm.mappers.ItemTypeMapper;
import com.hdax.dm.mappers.cinemaMapper;
import com.hdax.dm.mapstucts.floorDtoMapper;
import com.hdax.dm.service.floorService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class floorServiceImpl extends ServiceImpl<ItemTypeMapper, ItemType> implements floorService {

    @Autowired
    private floorDtoMapper floorDtoMapper;

    @Autowired
    private ItemServiceImpl itemService;

    @Autowired
    private imagefeign imagefeign;

    @Autowired
    private cinemaServiceImpl cinemaService;

    //    -----------------获取楼层数据---------------------
    @Override
    public CommonResponse<List<floorDto>> floor() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("parent",0L);

        List<ItemType> lists = baseMapper.selectList(queryWrapper);
        List<floorDto> dtos = floorDtoMapper.toTargetList(lists);

        Integer cinemaId = null;

        for (floorDto dto:dtos) {
            List<Item> Items =itemService.floor(dto.getItemTypeId());
            for (Item o:Items) {
                cinemaId=o.getCinemaId().intValue();
            }

            List<floorDto.items> libiao = floorDtoMapper.toItemList(Items);

            for (floorDto.items i:libiao) {
                image img = imagefeign.image(i.getId(),2L,1L);
                String imgUrl =img == null ? "":img.getImgUrl();
                i.setImgUrl(imgUrl);

                cinema c = cinemaService.selectOne(cinemaId);

                i.setAddress(c.getAddress());
                i.setAreaId(c.getAreaId());
                i.setAreaName(c.getAreaName());
            }
            dto.setItems(libiao);
        }
        return ResponseUtil.returnSuccess(dtos);
    }


}
